#include<bits/stdc++.h>
using namespace std;
const int N=200005;
int T,n;
int a[N], b[N], c[N];
int ans=-1;

int f()
{
    int temp=0;
    for (int i=1; i<=n; ++i)
    {
        for (int j=i-1; j>=1; --j)
        {
            if( b[i]==b[j] )
            {
                 if (a[i]==a[j]) c[i]=a[i];
                 break;
            }
        }
    }

    for (int i=1; i<=n; ++i)
    {
        temp+=c[i];
    }
    return temp;
}

void dfs(int x)
{
    if (x>n)
    {
        int temp=f();
        if (ans<temp) ans=temp;

        for(int i=0; i<=N; ++i) c[i]=0;
        return;
    }
    for (int i=1; i<=2; ++i)
    {
        b[x]=i;
        dfs(x+1);
    }
}

int main()
{
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    cin>>T;
    for (int g=1; g<=T; ++g)
    {
        cin>>n;
        for (int i=1; i<=n; ++i)
        {
            cin>>a[i];
        }
        dfs(1);

        cout<<ans<<'\n';
        for(int i=0; i<N; ++i)
        {
            a[i]=0; b[i]=0; c[i]=0;
        }
        ans=0;
    }
    return 0;
}
